<template>
  <el-dialog :title="editType === 'new' ? '添加蟹券信息' : '修改蟹券信息'"
    width="500px" :visible="true" :close-on-click-modal="false" @close="closeDialog(false)">
    <el-form :model="formInfo" label-position="left" label-width="100px">
      <!-- // 种类（包括苗、饲料、药物等下拉菜单）、名称、数量、来源 -->
      <el-form-item label="蟹券编号:">
        <el-input size="small" v-model="formInfo.id"></el-input>
      </el-form-item>
      <el-form-item label="蟹品总:">
        <el-input size="small" v-model="formInfo.type"></el-input>
      </el-form-item>

      <el-form-item label="蟹扣信息:">
        <p v-for="(item, index) in formInfo.ringId" :key="index">
          <el-input style="width: calc(100% - 40px)" size="small" v-model="formInfo.ringId[index]"></el-input>
          <i v-if="index > 0" @click="removeRing(index)" style="font-size: 20px" class="cursor ml10 el-icon-remove-outline"></i>
          <i v-else @click="addRing" style="font-size: 20px" class="cursor ml10 el-icon-circle-plus-outline"></i>
        </p>
      </el-form-item>
      <el-form-item label="生成日期:">
        <el-input size="small" v-model="formInfo.createTime"></el-input>
      </el-form-item>
      <el-form-item label="使用日期:">
       <el-input size="small" v-model="formInfo.useTime"></el-input>
      </el-form-item>
    </el-form>
     <span slot="footer" class="dialog-footer">
      <el-button
        type="primary"
        class="mr10"
        size="small"
      >
        确定
      </el-button>
      <el-button
        type="default"
        size="small"
        @click="closeDialog(false)"
      >
        取消
      </el-button>
    </span>
  </el-dialog>
</template>
<script>
export default {
  props: {
    editType: String,
    row: Object
  },
  created () {
    if (this.editType !== 'new') {
      Object.assign(this.formInfo, this.row)
    }
  },
  data () {
    return {
      formInfo: {
        ringId: ['']
      }
    }
  },
  methods: {
    closeDialog (flag = false) {
      const info = {
        type: 'launchModal',
        update: flag
      }
      this.$emit('modal-close', info)
    },
    addRing () {
      this.formInfo.ringId.push('')
    },
    removeRing (index) {
      this.formInfo.ringId.splice(index, 1)
    }
  }
}
</script>
<style lang="scss" scoped>
.cursor {
  cursor: pointer;
}
</style>
